<?php

/***  DOCUMENTATION LAYER

Apache Mod_Rewrite Testing

Last Update: Aug 2007
  
DESCRIPTION
  mod_rewrite must be enabled with appropriate htaccess settings
  
NOTES
  $test_root dynamically sets root in order to keep tests working after
  they are moved to the __REPOSITORY directory
    
______________________________________________________________________________*/

$_tx0 = microtime();
$test_root = ( strpos(dirname(__FILE__), 'repository') === false ) ? '' : '../';



function get_url_self($incq=1)
{
  $url = '';    // return

  // sanity checks
  if ( empty($_SERVER['SERVER_NAME']) ) { trigger_error('server name required', E_USER_ERROR); return 0; }
  
  // set parts
  $http = ( $_SERVER['HTTPS'] != '' ) ? 'https://' : 'http://';
  $host = $_SERVER['SERVER_NAME'];
  $qstr = ( $incq && !empty($_SERVER['QUERY_STRING']) ) ? "?{$_SERVER['QUERY_STRING']}" : '';
  #$path = ( !empty($_SERVER['REQUEST_URI']) ) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'].$qstr;
  $path = $_SERVER['PHP_SELF'].$qstr;
  
  // build full url
  $url = $http . $host . $path;
  
  // return
  return $url;
}
// END method




// Test Name
$test_name = 'rewrite testing';

// Configure Test
$debug = 1;


// *** Unit Test
print '<a href="'.get_url_self().'">'.get_url_self().'</a><br/>';
print '<a href="'.get_url_self(0).'">'.get_url_self(0).'</a><br/>';
print '<h3>GET</h3><pre>' . print_r($_GET, 1) . '</pre>';
print '<h3>SERVER</h3><pre>' . print_r($_SERVER, 1) . '</pre>';


// Footer
$_txn = microtime();
$stx = number_format(((substr($_txn,0,9)) + (substr($_txn,-10)) - (substr($_tx0,0,9)) - (substr($_tx0,-10))),4); 
echo "<h6>test '$test_name' complete in $stx s</h6>";
?>
